﻿#include "Thread.h"

using namespace Web;

void Thread::Start()
{
//	auto func = [&]()
//	{
//		mState = Thread::State::TH_WORKING;
//		Run();
//		mState = Thread::State::TH_END;
//	};
    this->mThread = new std::thread(Thread::RunTask, this);
}

void Thread::RunTask(Thread *task)
{
    task->Work();
}
void Thread::Work()
{
    mState = Thread::State::TH_WORKING;
    Run();
    mState = Thread::State::TH_END;
}



void Thread::Detach()
{
	mThread->detach();
}

void Thread::Join()
{
	if (mThread->joinable())
	{
		mThread->join();
	}
}

bool Thread::Joinable()
{
    return mThread->joinable();
}

Thread::~Thread()
{
    delete mThread;
}


